<?php
	class tructuyendb
	{
		// Khai báo các phương thức (nên có giá trị mặc định cho đối số)
		public function Add($MaSession = "", $TimeOut = 0)
		{
			$sql = "INSERT INTO tbl_tructuyen(MaSession, TimeOut) VALUES('" . $MaSession . "', " . (time()  + $TimeOut) . ")";
			
			$db = new dataservice();
			return $db->ExecuteNonQuery($sql);
		}
		
		public function Update($MaSession = "", $TimeOut = 0)
		{
			$sql = "UPDATE tbl_tructuyen SET TimeOut = " . (time()  + $TimeOut) . " WHERE MaSession = '" . $MaSession . "'";
			
			$db = new dataservice();
			return $db->ExecuteNonQuery($sql);
		}
		
		public function countOnline()
		{
			$sql	= "SELECT count(*) SoLuotOnline from tbl_tructuyen WHERE (1) and TimeOut >= " . time();
			
			$db = new dataservice();
			return $db->ExecuteQuery($sql);
		}
		
		public function Test($MaSession = "")
		{
			$sql = "select * from tbl_tructuyen where (1) and MaSession = '" . $MaSession . "'";
			
			$db = new dataservice();
			return $db->ExecuteNonQuery($sql);
		}
		
		public function Delete()
		{
			$sql	= "delete from tbl_tructuyen where (1) and TimeOut < " . time();
			
			$db = new dataservice();
			return $db->ExecuteNonQuery($sql);
		}
	}
?>